package com.gxan.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.gxan.common.JsonResult;
import com.gxan.service.HouseService;
import com.gxan.service.impl.HouseServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*
按照户主名查询房产列表并分页
 */
@WebServlet("/house/search")
public class SearchHouseServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //按照户主名查询
        String huzhu_name = request.getParameter("huzhu_name");
        //接收当前页码和每页显示条数
        int currentPage = Integer.parseInt(request.getParameter("page"));
        int pageSize = Integer.parseInt(request.getParameter("limit"));
        //调用Service
        HouseService houseService = new HouseServiceImpl();
        JsonResult jsonResult = houseService.queryHouseList(currentPage, pageSize,huzhu_name);
        //转成JSON
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(JSONObject.toJSONString(jsonResult));
    }
}
